package com.gzsxy.esjy.bus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gzsxy.esjy.bus.dao.OperlogMapper;
import com.gzsxy.esjy.bus.entity.OperLogQueryVo;
import com.gzsxy.esjy.bus.service.IOperlogService;
import com.gzsxy.esjy.service.base.dto.request.LoginLogRequest;
import com.gzsxy.esjy.service.base.dto.request.OperlogRequest;
import com.gzsxy.esjy.service.base.dto.response.PageResult;
import org.springframework.stereotype.Service;

/**
 * @author xiaolong
 * @version 1.0
 * @description: 操作日志
 * @date 2022/5/3 14:10
 */
@Service
public class IOperlogServiceImpl  extends ServiceImpl<OperlogMapper, OperlogRequest> implements IOperlogService {



    @Override
    public void addOperlog(OperlogRequest operlogRequest) {
        baseMapper.insert(operlogRequest);
    }

    /**
     * @description: 分页查询当前操作日志
     * @param
     * @return
     */
    @Override
    public PageResult<OperlogRequest> getPageVo(IPage<OperlogRequest> pageParam, OperLogQueryVo operLogQueryVo) {
        LambdaQueryWrapper<OperlogRequest> wrapper = Wrappers.lambdaQuery();
        if (StringUtils.isNotBlank(operLogQueryVo.getUserName())){
            wrapper.eq(OperlogRequest::getOperUserName,operLogQueryVo.getUserName());
        }
        if (StringUtils.isNotBlank(operLogQueryVo.getStatus())){
           wrapper.eq(OperlogRequest::getStatus,operLogQueryVo.getStatus());
        }
        wrapper.orderByDesc(OperlogRequest::getCreateTime);
        IPage<OperlogRequest> page = baseMapper.selectPage(pageParam, wrapper);
        PageResult<OperlogRequest> pageResult = new PageResult<>();
        pageResult.setRecords(page.getRecords());
        pageResult.setTotal(page.getTotal());
        return pageResult;
    }
}
